#include "ActionRecord.h"

namespace LightPlayer{

	ActionRecord::ActionRecord(){
		init();
	}

	void ActionRecord::init(){
		m_ActionCode = eActionEnd;
		m_Data.init();
	}

	void ActionRecord::readFromStream( Stream* stream ){
		init();
		SetActionCode( stream->read_u8() );
		uint16 length = 0;
		if( m_ActionCode >= 0x80 ){
			length = stream->read_u16();
			m_Data.init( stream->getCurrentPosition(), length );
			stream->skip_byte( length );
		}
	}

	ActionList::ActionList(){
		init();
	}

	void ActionList::init(){
		clear();
	}

	void ActionList::clear(){
		for (uint32 i=0; i<m_ActionList.size(); ++i){
			m_ActionRecordListPool.FreeObject( m_ActionList[i] );
		}
		m_ActionList.clear();
		m_ActionRecordListPool.clear();
	}

	void ActionList::push_back( const uint8* start_actions, uint32 size_of_actions ){
		ActionRecordList* newActionsList = m_ActionRecordListPool.getNew();
		newActionsList->init( start_actions, size_of_actions );
		m_ActionList.push_back( newActionsList );
	}

	uint32 ActionList::size(){
		return m_ActionList.size();
	}

};